import {
  cmdInvoker,
  MenuItemDefinition,
  ObjectTreeMenuProps,
} from '@amcax/base';
import { docMgr, userEvents } from '@app-cad/module';
import { ContextMenuEvents } from './events';

export const MenuItemShowRelations: MenuItemDefinition<ObjectTreeMenuProps> = {
  id: 'relation',
  children: '父级/子级',
  hidden: ({ props: { documentObject, selectedObjects } }) => {
    return (
      selectedObjects.length > 1 || // multiple selection
      !!docMgr.getCurrentSketchDxid() || // in sketch mode
      (!documentObject.prelinks?.length && !documentObject.outlinks?.length) // no relations
    );
  },

  onClick: ({ props: { documentObject } }) => {
    if (cmdInvoker.currentCmd) {
      cmdInvoker.resetCmd();
    }

    userEvents.emit(ContextMenuEvents.ShowRelations, documentObject);
  },
};
